package com.example.controller;

import com.example.model.Course;
import com.example.model.TeacherCourse;
import com.example.service.CourseService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/course")
public class CourseController {
    private final CourseService courseService;
    public CourseController(CourseService courseService){
        this.courseService=courseService;
    }
    @PostMapping("/create")
    public void create(@RequestBody Course course){
        courseService.createCourse(course);
        System.out.println(course);
    }
    @GetMapping("/delete")
    public void delete(@RequestParam(value = "courseId") String courseId){
        courseService.deleteCourse(courseId);
    }
    @PostMapping("/update")
    public void update(@RequestBody Course course){
        courseService.updateCourse(course);
    }
    @PostMapping("/join")
    public String join(@RequestBody TeacherCourse teacherCourse){
         return courseService.joinCourse(teacherCourse);
    }
    @GetMapping("/allCourse")
    public List<Course> selectAllCourse(@RequestParam(value = "number")String number){
        return courseService.select(number);
    }
    @GetMapping("/crateAll")
    public  List<Course> createAllCourse(@RequestParam("Tid")String Tid){
        return courseService.selectAllCourse(Tid);
    }
}
